fix: ensure route chunk names are relative instead of absolute paths - #112
Closed
alvadorn wants to merge 1 commit into
Closed
fix: ensure route chunk names are relative instead of absolute paths#112alvadorn wants to merge 1 commit into
alvadorn wants to merge 1 commit into
Conversation
`relative()` from `@react-router/dev/routes` resolves route files to absolute paths, so React Router relativizes `file` but leaves `id` absolute. The plugin used that opaque id as an rspack entry name, so split route module chunks were emitted into a directory tree mirroring the developer's checkout, and the browser manifest published those paths -- leaking $HOME into production assets and making builds unreproducible across machines and CI. The main route entry already derived its name from `route.file`, twenty lines above the chunk entry that derived it from `route.id`. Both now go through one shared `getRouteEntryBaseName`, so a chunk lands beside its route, the `/static/js//...` double slash is gone, and an entry can no longer escape the JS output directory or carry a Windows drive prefix. Routes sharing a file now share one chunk instead of emitting byte-identical duplicates. Route ids are untouched: they remain the runtime contract behind `useRouteLoaderData(id)` and `matches[].id`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
With
splitRouteModulesenabled, routes usingrelative()without an explicitidemit absolute filesystem paths as part of their chunk names (e.g.,/Users/<user>/...). This breaks build reproducibility, causes invalid asset URLs (double slashes), and leaks local path structures.Root Cause
The plugin used
route.idas the entry filename. While the manifest relativizesroute.file, it keepsroute.idabsolute. Whenrelative()is used, theidbecomesan absolute path, which the plugin then treated as a directory tree for the output.
The Fix
Introduced
getRouteEntryBaseName(route, appDirectory)to derive both the main route entry and its chunks from a shared, relative base.This shared helper also adds safety against:
static/js/.C:\).Behavior Change
ids now use file-based names instead ofid-based names. This is a rename, not a logic change.id.Tests